layui.use(['form','tree','element','table','laytpl','treeGrid','layer','jquery'],function(){
    var form = layui.form,
        element = layui.element;
    $ = layui.$;
    var layer = parent.layer === undefined ? layui.layer : top.layer;
    var table = layui.table;
    var laytpl = layui.laytpl;
    var layedit = layui.layedit;

    //列表数据
    var option = {
        elem: '#tableList',
        url : '/produce/batch/page',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limits : [10,15,20,25],
        limit : 15,
        id : "listTable",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            /*{field: 'id', title: '批次编号', minWidth:100, align:"center"},*/
            {field: 'produceName', title: '产品批次名称', minWidth:100, align:"center"},
            {field: 'originNumber', title: '批次数量', minWidth:100, align:"center"},
            {field: 'finallyNumber', title: '最终出产数量', minWidth:100, align:"center"},
            {field: 'batchStatus', title: '状态', minWidth:100, align:"center", templet:function(d){
                   if (d.batchStatus == 0) {
                       return '<span style="color: red;">待生产</span>'
                   } else if(d.batchStatus == 1) {
                       return '<span style="color: dodgerblue;">生产中</span>'
                   } else {
                       return '<span>完成</span>'
                   }
                }},
            {field: 'responsiblePerson', title: '负责人', minWidth:100, align:"center"},
            {field: 'regulatoryAuthorities', title: '监管部门', minWidth:100, align:"center"},
            {title: '操作', minWidth:280, fixed:"right",align:"center",templet:'#tableListBar'}
        ]]
    };

    //产品批次列表
    var tableIns = table.render(option);

    //搜索产品批次信息
    $(".search_btn").on("click",function(){
        var searchKey = $(".searchVal").val();
        if(searchKey != ''){
            option.url = '/produce/batch/query';
            option.method = 'post';
            option.where = {produceName: searchKey};
            table.render(option);
        }else{
            layer.msg("请输入搜索的内容");
        }
    });

    //列表操作
    table.on('tool(tableList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
        if(layEvent === 'qrcode-manager'){
            //打开二维码定制页面
            var index = layui.layer.open({
                title: "生产环节二维码定制--当前批次：" + data.produceName,
                type: 2,
                content: "recordQrcodeList?id=" + data.id + "&processTemplateId=" + data.processTemplateId,
                area: ['100%',($(document).height() - 40) + 'px'],
                success: function () {
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回产品批次列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500);
                }
            });
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(index);
            });
        }
    });

});